<template>
	<div class="auditDetail" v-loading="loading">
		<div class="left">
			<div class="left-top">
				<el-descriptions>
					<el-descriptions-item label="标题：">{{ article.title }}</el-descriptions-item>
					<el-descriptions-item >
						<div >
                			<el-button @click="back(name)">返回</el-button>
            			</div>
					</el-descriptions-item>
				</el-descriptions>
				<el-descriptions>
					<el-descriptions-item label="作者：">{{ article.author }}</el-descriptions-item>
					<el-descriptions-item label="创建时间：">{{ article.addTime }}</el-descriptions-item>>
					<el-descriptions-item label="审核状态：">
						<template #default="scope">
					    	<span v-if="article.audit === '0'" style="color: #FFC300;">待审核</span>
							<span v-else-if="article.audit === '1'" style="color: #60DBB0;">审核通过</span>
							<span v-else-if="article.audit === '2'" style="color: #FF4F6D;">审核不通过</span>
						</template>
					  <!-- <el-tag size="small" color="rgba(255,195,0,0.05)"><span style="color: #FFC300;">{{ article.state }}</span></el-tag> -->
					</el-descriptions-item>
				</el-descriptions>
			</div>
            <h4>文章内容：</h4>
			<div class="content" v-html="article.content">
				
			</div>
		</div>
		<div class="right" v-if="article.audit === '0'">
            <div class="right-bottom">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="审核意见：" label-width="100px">
                        <el-radio-group v-model="form.audit">
                        <el-radio label="1">审核通过</el-radio>
                        <el-radio label="2">审核不通过</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="备注：">
                        <el-input type="textarea" :rows="10" v-model="form.note"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit(article.id)" :disabled="form.audit === ''">确认审核</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
	</div>
</template>

<script>
	import { getArticleDetail, editArticle } from '../../request/api/articleMange/articleMange.js'
	import {getCurrentTime} from '../../utils/index.js'

	export default {
		data() {
			return {
				article: {},
				name: '',
                form: {
                    audit: '',
                    note: ''
                },
                loading: false,
			}
		},
		created() {
			this.getArt()
		},
		methods: {
			// 读取文章
			async getArt() {
                this.loading = true
				const id = this.$route.query.id
				this.name = this.$route.query.pathname
				const { data } = await getArticleDetail({id})
				if (data) {
					if (data.code === 0) {
						this.article = data.art
                        this.loading = false
					}
				} else {
					this.loading = false
				}
			},
			// 确认审核
            async onSubmit(id) {
				console.log(id)
				const form = {
					id,
					auditTime: getCurrentTime(),
					...this.form
				}
				const { data } = await editArticle(form)
				if (data) {
					if (data.code === 0) {
						this.$message({
							message: '审核成功',
							type: 'success'
						})
						this.$router.push({path: '/home/manage/audit'})
					}
				} else {
					 this.$message({
						message: '审核失败',
						type: 'warning'
					})
				}
            },
			// 返回
            back(pathname) {
                this.$router.push({ name: pathname })
            }
		},
	}
</script>

<style lang="scss" scoped>
	.auditDetail {
		display: flex;
		justify-content: space-between;
        padding: 14px;
        box-sizing: border-box;
		.left {
			flex: 6.5;
			.left-top {
				height: 110px;
                .el-tag {
                    border: 1px solid #FFC300;
                }
			}
            h4 {
                height: 25px;
                padding-bottom: 10px;
            }
			.content {
				height: calc(100% - 115px);
				overflow-y: scroll;
			}
		}
		.right {
            padding: 0 30px 30px;
			flex: 3.5;
			margin-top: 120px;
            .right-top {
                height: 105px;
                display: flex;
                justify-content: end;
            }
            .right-bottom {
                height: calc(100% - 115px);
            }
		}
	}
</style>